package com.sccomsumer.comsumer.Hystrix;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.sccomsumer.comsumer.service.UserCommonHystrixService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class HystrixController {
//    @Qualifier("provider")
    @Autowired()
    private UserCommonHystrixService hystrixService;
    @Autowired
    private HystrixService service;

    /**
     * 使用restTemplate进行整合。
     *
     * @return
     */
    @GetMapping("/alive")
    @HystrixCommand(fallbackMethod = "back")
    public String alive() {
        return service.alive();
    }

    public String back() {
        return "404,出错啦！";
    }


    @GetMapping("/testAlive")
    public String alive2() {
        return hystrixService.testHystrix();
    }

}
